﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnimalCare.Model;

namespace AnimalCare.Service
{
    class PositionService
    {
        public static void Insert(string classificationName)
        {
            Position cf = new Position();
            cf.position_name = classificationName;
            using (var ctx = new AnimalCareDBEntities())
            {
                ctx.Positions.AddObject(cf);
                ctx.SaveChanges();
            }
        }

        public static void Update(Position cf)
        {
            using (var ctx = new AnimalCareDBEntities())
            {
                var position = (from s in ctx.Positions
                                where s.position_id == cf.position_id
                                select s).FirstOrDefault();
                position.position_name = cf.position_name;
                int num = ctx.SaveChanges();
            }
        }

        public static void Delete(int id)
        {
            try
            {
                using (var ctx = new AnimalCareDBEntities())
                {
                    var cf = (from s in ctx.Positions
                              where s.position_id == id
                              select s).FirstOrDefault();
                    ctx.Positions.DeleteObject(cf);
                    int num = ctx.SaveChanges();
                }
            }
            catch
            {
            }
        }
    }
}
